package cn.com.bluemoon.daps.standard.api.factory;

import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiStandard;
import cn.com.bluemoon.daps.common.domain.PageVo;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.standard.api.RemoteStandardBasicService;
import cn.com.bluemoon.daps.standard.entity.DapStandardBasic;
import cn.com.bluemoon.daps.standard.vo.BasicStandardFormVo;
import cn.com.bluemoon.daps.standard.vo.StandardInfoVo;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 标准服务降级处理
 *
 * @author Jarod Kong
 */
@Component
public class RemoteStandardFallbackFactory implements FallbackFactory<RemoteStandardBasicService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteStandardFallbackFactory.class);

    @Override
    public RemoteStandardBasicService create(Throwable throwable) {
        log.error("数据标准-主题分类调用失败:{}", throwable.getMessage());
        return new RemoteStandardBasicService() {

            @Override
            public ResultBean<DapStandardBasic> getBasic(String id) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiStandard.PROD_SERVICE, "第三方服务调用-获取标准数据失败");
            }

            @Override
            public ResultBean getPublishBasicStd(BasicStandardFormVo<?> formVo) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiStandard.PROD_SERVICE, "第三方服务服务调用-获取基础标准已发布的数据失败");
            }

            @Override
            public ResultBean<PageVo<StandardInfoVo>> pageBasicStd(String keyword, Integer pageNo, Integer pageSize) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiStandard.PROD_SERVICE, "获取基础标准信息失败");
            }

            @Override
            public ResultBean<PageVo<StandardInfoVo>> pageIndexStd(String keyword, Integer pageNo, Integer pageSize) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiStandard.PROD_SERVICE, "获取指标标准信息失败");
            }

        };
    }
}
